﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands.轮播图;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.轮播图
{
    public class DeleteCarouselCommandHandler : IRequestHandler<DeleteCarouselCommand, APIResult<int>>
    {
        private readonly IBaseRespository<CarouselModel> carRep;

        public DeleteCarouselCommandHandler(IBaseRespository<CarouselModel> carRep)
        {
            this.carRep = carRep;
        }

        public async Task<APIResult<int>> Handle(DeleteCarouselCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code=ResultCode.删除成功;
            result.Message=ResultCode.删除成功.ToString();

            var res=carRep.GetAll().FirstOrDefault(x=>x.CarouselId==request.CarouselId);
            res.IsDeleted=true;
            await carRep.UpdateAsync(res);


            return await Task.FromResult(result);
        }
    }
}
